#include "DateTimeSetView.h"
#include "ui_DateTimeSetForm.h"


DateTimeSetView::DateTimeSetView(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::DateTimeSet)
{
    ui->setupUi(this);
    this->setWindowFlags(Qt::FramelessWindowHint);
    m_settingHelper = SettingHelper::getSettingHelper();
    readSetting();
}

DateTimeSetView::~DateTimeSetView()
{
    delete ui;
}

void DateTimeSetView::readSetting()
{
    m_settingHelper->dateTimeReadSetting();
    QString dateStr = m_settingHelper->m_DateTimeSet.date;
    QString timeStr = m_settingHelper->m_DateTimeSet.time;
    ui->nu_DateEdit->setDateTime(QDateTime::fromString(dateStr,"yyyy-MM-dd"));
    ui->nu_TimeEdit->setDateTime(QDateTime::fromString(timeStr,"hh-ss"));
    //ui->comboBox_timeForm->setCurrentText(m_settingHelper->m_DateTimeSet.format);
}

void DateTimeSetView::writeSetting()
{
    m_settingHelper->m_DateTimeSet.date = ui->nu_DateEdit->text();
    m_settingHelper->m_DateTimeSet.time = ui->nu_TimeEdit->text();
    m_settingHelper->m_DateTimeSet.format = ui->comboBox_timeForm->currentText();

    m_settingHelper->dateTimeWriteSetting();
}

void DateTimeSetView::closeEvent(QCloseEvent *e)
{
    Q_UNUSED(e);
    writeSetting();
}
